home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: delta / whiteline CD Series - delta.iso / tools / utils / smc_tt1 / smclance.c < prev    next >
C/C++ Source or Header  |  1995-11-25  |  6KB  |  222 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <tos.h>
  5. #include "..\include\lan.h"
  6. #include "..\include\cookie.h"
  7. #include "..\include\wd.h"
  8. #include "..\include\fifo.h"
  9. #include "..\include\driver.h"
  10.  
  11. extern void  wd_get_lan_addr(unsigned char *eth_addr);
  12. extern int wd_send(unsigned char *buffer,unsigned short len);
  13. extern int  wd_init(void);
  14.  
  15. /*-------------------------------------------------------------*/
  16. /* globale Variablen fuer Packetpool                           */
  17. /*-------------------------------------------------------------*/
  18. ff_typ    ff_free;                      /* FIFO der freien Pakete*/
  19.  
  20. et_stat statistics;                   /* Statistik             */
  21.  
  22. PROTOCOL protos[MAXPROTOCOLS];        /* protocols to serve    */
  23. int protocols = 0;                    /* number of active protocols */
  24.  
  25. char free_mem[MAXPKT*2048L];   /* Paketpuffer           */
  26.  
  27. static unsigned char send_sema=0;     /* Sendesemaphor         */
  28.  
  29. /*-------------------------------------------------------------*/
  30. /* Tabelle mit Funktionszeigern, auf den das Cookie zeigt      */
  31. /*-------------------------------------------------------------*/
  32. procref ext_tab[8] =
  33. {
  34.   net_reset,
  35.   net_open,
  36.   net_release,
  37.   net_send,
  38.   net_getadr,
  39.   net_info,
  40.   (procref)net_pktalloc,
  41.   net_pktfree
  42. };
  43.  
  44. /*-------------------------------------------------------------*/
  45. /* Text auf Bildschirm ausgeben (nur Initialisierung)          */
  46. /*-------------------------------------------------------------*/
  47. void debug_str(char *str)
  48. {
  49. Cconws(str);
  50. Cconws("\n\r");
  51. }
  52.  
  53. /*-------------------------------------------------------------*/
  54. /* Gibt auskunft ueber den aktuelle Netzstatus                 */
  55. /*-------------------------------------------------------------*/
  56. int net_info(int len, et_stat *buf)
  57. {
  58. if(len < sizeof(statistics) )
  59.   return EPARAM;
  60. memcpy(buf,&statistics,sizeof(statistics));
  61. return 0;
  62. }
  63.  
  64. /*-------------------------------------------------------------*/
  65. /* Installieren eines Protokollhandlers                        */
  66. /*-------------------------------------------------------------*/
  67. int net_open(int type, int (*handler)(int,lan_buffer_typ *))
  68. {
  69. int        i;
  70.  
  71. if(protocols >= MAXPROTOCOLS) return EPROTAVAIL;
  72.  
  73. for(i = 0; i < MAXPROTOCOLS; i++)
  74.   {    /* protocol ist schon angemeldet */
  75.   if(protos[i].type == type)
  76.     return(EPROTUSED);
  77.   }
  78.  
  79. for(i = 0; i < MAXPROTOCOLS; i++)
  80.   if(protos[i].type == ET_UNUSED)  /* find first free entry */
  81.     {
  82.     protocols++;
  83.     protos[i].handler = handler;
  84.     protos[i].recvd = 0;
  85.     protos[i].sent = 0;
  86.     protos[i].type = type;
  87.     return(i);
  88.     }
  89. return EPROTAVAIL;
  90. }
  91.  
  92. /*-------------------------------------------------------------*/
  93. /* Entfernen eines Protokollhandlers                           */
  94. /*-------------------------------------------------------------*/
  95. int net_release(int type)
  96. {
  97. int i;
  98.  
  99. if(!protocols) return(EPROTUSED);
  100. if(type == ET_UNUSED) return(EPROTUSED);
  101.  
  102. for(i=0; i < MAXPROTOCOLS; i++)
  103.   if(protos[i].type == type) break;
  104. if(i==MAXPROTOCOLS)
  105.   return(EPROTUSED);
  106.  
  107. protocols--;
  108.  
  109. protos[i].type = ET_UNUSED;
  110. protos[i].handler = NULL;
  111. return(protocols);
  112. }
  113.  
  114. /*-------------------------------------------------------------*/
  115. /* Paket senden                                                */
  116. /*-------------------------------------------------------------*/
  117. int net_send(int len, lan_buffer_typ *buf)
  118. {
  119. int erg;
  120.  
  121. get_sema(&send_sema);
  122. erg = wd_send((unsigned char*)buf,(unsigned short)len);
  123. clear_sema(&send_sema);
  124. return erg;          /* return = tatsaechlich gesendete laenge */
  125. }
  126.  
  127. /*-------------------------------------------------------------*/
  128. /* Ethernetaddresse des eigenen Adapters ermitteln             */
  129. /*-------------------------------------------------------------*/
  130. int    net_getadr(int len, unsigned char *buf)
  131. {
  132. if(len < 6) return 0;    /* sicherheitshalber                  */
  133. wd_get_lan_addr((unsigned char*)buf);
  134. return 6;            /* Ethernet hat 6 Byte Adresse            */
  135. }
  136.  
  137. /*-------------------------------------------------------------*/
  138. /* Adapter zurücksetzen                                        */
  139. /*-------------------------------------------------------------*/
  140. int net_reset(void)
  141. {
  142. int i;
  143.  
  144. for(i=0;i<MAXPROTOCOLS;i++)  /* init protocol table */
  145.   {
  146.   protos[i].type = ET_UNUSED;
  147.   protos[i].handler = NULL;
  148.   protos[i].recvd = 0;
  149.   protos[i].sent = 0;
  150.   }
  151. protocols = 0;
  152.  
  153. pkt_ff_init(&ff_free,MAXPKT);   /* leeren FIFO anlegen */
  154. pkt_ff_alloc(&ff_free,free_mem);         /* FIFO mit freien Paketen fⁿllen */
  155.  
  156. wd_init();        /* Init WD Chipsatz */
  157.  
  158. return 0;                   /* OK, reset OK */
  159. }
  160.  
  161. /*--- Supexec braucht long Funktion ---------------------------*/
  162. long net_reset_s(void)
  163. {
  164. return (int) net_reset();
  165. }
  166.  
  167. /*-------------------------------------------------------------*/
  168. /* Speicherplatz fuer ein Paket des angegebenen Protokolles    */
  169. /* allokieren                                                  */
  170. /*-------------------------------------------------------------*/
  171. lan_buffer_typ *net_pktalloc(unsigned short protocol)
  172. {
  173. protocol = protocol;          
  174. return pkt_ff_get(&ff_free);  /* Protokoll wird ignoriert       */
  175. }
  176.  
  177. /*-------------------------------------------------------------*/
  178. /* Speicherplatz eines Paketes freigeben                       */
  179. /*-------------------------------------------------------------*/
  180. int net_pktfree(lan_buffer_typ *p_pkt)
  181. {
  182. return pkt_ff_put(&ff_free,p_pkt);
  183. }
  184.  
  185. /*-------------------------------------------------------------*/
  186. /* Hauptprogramm des Treibers                                  */
  187. /*-------------------------------------------------------------*/
  188. int main()
  189. {
  190. COOKIE *cookie;
  191. char str[100];
  192.  
  193. Cconws("\r\nUlrichs Ethercard Elite Treiber \r\n");
  194. cookie = get_cookie(PKTCOOKIE);
  195.  
  196. if(cookie)
  197.   {
  198.   Cconws("\r\!!! COOKIE existiert noch !!!, das wird nix!\r\n");
  199.   exit(0);
  200.   }
  201. else
  202.   {
  203.   if(Supexec(net_reset_s) < 0)
  204.     {
  205.     Cconws("\r\n Fehler beim Initialisiern der Karte\r\n");
  206.     Cconws("\r\n Weiter mit taste\r\n");
  207.     gets(str);
  208.     exit(0);
  209.     }
  210.  
  211.   add_cookie(PKTCOOKIE,(long)ext_tab);
  212.  
  213.   Cconws("Cookie installed\r\n");
  214.   }
  215.  
  216. sprintf(str,"%ld Bytes resident\n",_PgmSize);
  217. Cconws(str);
  218. Ptermres(_PgmSize,0);
  219. return 0;
  220. }
  221.  
  222.